package com.anycl.design.behavioral.observer.instance;

import java.util.ArrayList;
import java.util.List;

public class Platform implements IPlatform {
    private List<IReader> list = new ArrayList<>();

    @Override
    public void attach(IReader reader) {
        list.add(reader);
    }

    @Override
    public void detach(IReader reader) {
        list.remove(reader);
    }

    @Override
    public void notifyReaders(String bookName) {
        for (IReader reader: list)
            reader.update(bookName);
    }

    public void change(String bookName) {
        this.notifyReaders(bookName);
    }
}
